<?php
defined('IN_LK') or die('Access Denied');
class admin_op
{
	private $admin_db;
	
	public function __construct()
	{
		$this->admin_db = lk::load_model('admin');
	}
	
	/**
	 * 修改密码
	 */
	final public function edit_pwd($userid, $pwd)
	{
		$userid = (int)$userid;
		if($userid <1)
		{
			return false;
		}
		if(!is_password($pwd))
		{
			showmsg(LANG('password_not_allow'), false, HTTP_REFERER);
		}
		$pwd = password($pwd);
		return $this->admin_db->update(array('password'=>$pwd), "`userid`='$userid'");
	}
	
	/**
	 * 检查旧密码是否正确 正确返回true
	 */
	final public function is_right_oldpwd($userid, $pwd)
	{
		$userid = (int)$userid;
		if($userid <1)
		{
			return false;
		}
		$pwd = password($pwd);
		return $this->admin_db->get_one('userid', "`password`='$pwd' AND `userid`='$userid'");
	}
	
	/**
	 * 检查用户名是否存在 存在返回true
	 */
	final public function is_username_exists($username)
	{
		$r = $this->admin_db->get_one('userid', "`username`='$username'");
		return (boolean)$r ? true : false;
	}
	
	/**
	 * 检查Email是否存在 存在返回true
	 */
	final public function is_email_exists($email)
	{
		$r = $this->admin_db->get_one('userid', "`email`='$email'");
		return (boolean)$r ? true : false;
	}
}